from time import sleep
import uiautomation
import pyautogui

class yizhuzhixing():
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        his.SetFocus()

        yizhuzhixingchuangkou = his.WindowControl(ClassName='Window',Name='执行医嘱')
        keshi = yizhuzhixingchuangkou.ComboBoxControl(AutomationId='cmb_lsyz',ClassName='ComboBox')
        yizhuleixing = yizhuzhixingchuangkou.ComboBoxControl(AutomationId='adviceType',ClassName='ComboBox')
        yizhuzhangtai = yizhuzhixingchuangkou.ComboBoxControl(AutomationId='adviceStatus',ClassName='ComboBox')
        yizhufenlei = yizhuzhixingchuangkou.ComboBoxControl(ClassName='ComboBox',foundIndex=3)
        huanzhexingming = yizhuzhixingchuangkou.EditControl(ClassName='TextBox')
        chaxun = yizhuzhixingchuangkou.ButtonControl(AutomationId='btn_query',ClassName='Button')
        zhixing = yizhuzhixingchuangkou.ButtonControl(AutomationId='btn_save',ClassName='Button',Name='执行')

        shuju1 = his.DataGridControl(ClassName='YDataGrid').DataItemControl(ClassName='DataGridRow').CustomControl(SubName='列显示索引: 0',ClassName='DataGridCell')


        #温馨提示窗口
        wenxintishichuangkou =  his.WindowControl(Name='温馨提示')
        wenxintishichuangkouqueding = wenxintishichuangkou.ButtonControl(AutomationId='YesBtn',ClassName='Button',Name='是')
        wenxintishichuangkouquxiao = wenxintishichuangkou.ButtonControl(AutomationId='NoBtn',ClassName='Button',Name='否')
        #点击数据1
        def click_sj1(self):
                self.shuju1.Click()
        #选择科室
        def choose_ks(self,ks):
                self.keshi.Click()
                self.keshi.SendKeys(ks)
                sleep(1)
                pyautogui.press("enter")
        #选择医嘱类型
        def choose_yzlx(self,yzlx):
                self.yizhuleixing.Select(yzlx)

        #选择医嘱状态
        def choose_yzzt(self,yzzt):
                self.yizhuzhangtai.Select(yzzt)
        #选择医嘱分类
        def choose_yzfl(self,yzfl):
                self.yizhufenlei.Select(yzfl)
        #输入患者姓名
        def input_hzxm(self,hzxm):
                self.huanzhexingming.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.huanzhexingming.SendKeys(hzxm)
        #点击查询
        def click_cx_btn(self):
                self.chaxun.Click()
        #点击执行
        def click_zx_btn(self):
                self.zhixing.Click()

        #关闭窗口
        def close_window(self):
                self.yizhuzhixingchuangkou.GetWindowPattern().Close()



        #点击温馨提示确定按钮
        def click_tsqd_btn(self):
                self.wenxintishichuangkou.Refind()
                self.wenxintishichuangkouqueding.Refind()
                self.wenxintishichuangkouqueding.Click()

        # 点击温馨提示取消按钮
        def click_tsqx_btn(self):
                self.wenxintishichuangkou.Refind()
                self.wenxintishichuangkouquxiao.Refind()
                self.wenxintishichuangkouquxiao.Click()

        #执行医嘱
        def execute_yz(self,yzlx):
                self.choose_yzlx(yzlx)  #选择医嘱类型
                self.click_cx_btn()     #点击查询
                self.click_sj1()        #点击数据1
                self.click_zx_btn()     #点击执行
                self.click_tsqd_btn()   #点击提示确定按钮